//
//  ZLightVC.m
//  ZZBlue
//
//  Created by stonesMonkey on 2017/9/10.
//  Copyright © 2017年 stonesMonkey. All rights reserved.
//

#import "ZLightVC.h"
#import "ZZOpenView.h"
#import "ZZHomeTopView.h"
#import "ZZLightViewSettingVC.h"
#import "ZZLightViewGroupModel.h"
#import "ZZLightViewCellModel.h"
#import "ZZLightViewCell.h"
#import "ZZColorRGBA.h"
#import "ZZLightColorTool.h"
#import "BleManage.h"
#import "Timerobj.h"
#import "ZZDeviceManager.h"
#import "ZZLightLineTool.h"
#import "ZZLightLineGroupModel.h"
#import "ZZLightLineModel.h"
#import "ZZLightLineCell.h"
#import "ZZLightLineSettingVC.h"
#import "ZZLightViewTool.h"

#define kZZLightViewIdentifier @"ZZLightViewCell"
#define kZZLightLineViewIdentifier @"ZZLightLineViewIdentifier"

@interface ZLightVC ()<UICollectionViewDelegate,UICollectionViewDataSource,UITableViewDelegate,UITableViewDataSource>{
    float paomaAspeedvalue;
}

@property (weak, nonatomic) IBOutlet UIView *topView;

@property (weak, nonatomic) IBOutlet UIButton *topViewLeftBtn;

@property (weak, nonatomic) IBOutlet UIButton *topViewRightBtn;

@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;

@property (weak, nonatomic) IBOutlet UIView *bottomView;

@property (nonatomic, strong)ZZHomeTopView *progreesView;

@property (nonatomic, strong)ZZLightViewGroupModel *groupModel;

@property (weak, nonatomic) IBOutlet UICollectionViewFlowLayout *flowLayout;

@property (nonatomic, weak)ZZDeviceManager *devicemanager;

@property (nonatomic ,assign) BOOL isLightLine;

#pragma mark - LightLine数据模型
@property (weak, nonatomic) IBOutlet UITableView *tableView;

@property (nonatomic ,strong) ZZLightLineGroupModel *lineGroupModel;

@end

@implementation ZLightVC
extern BleManage *bleManage;
extern  Timerobj *timermange;
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.titleView = [UIImageView zImageViewWithImage:@"img_logo"];
    
    ZZOpenView *openView = [ZZOpenView xibInstance];
    openView.frame = CGRectMake(0, 0, 66, 32);
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:openView];
    openView.onClick = ^{ // 点击了开
        
        
    };
    
    openView.offClick = ^{ // 点击了关
        
        
    };
    
    
    self.navigationItem.rightBarButtonItem =  self.navigationItem.rightBarButtonItem = [self zNavItemWithImage:@"icon_lanmu" shouldOriginal:YES andSelector:@selector(rightNavItemClick)];
    
    [self setupSubView];

    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.hidden = YES;
    self.tableView.backgroundColor = [UIColor blackColor];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

    [self.tableView registerNib: [UINib nibWithNibName:@"ZZLightLineCell" bundle:nil] forCellReuseIdentifier:kZZLightLineViewIdentifier];
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    if (self.progreesView == nil) {
        
        self.progreesView = [ZZHomeTopView xibInstance];
        self.progreesView.frame = self.bottomView.bounds;
        [self.progreesView.sliderView addTarget:self action:@selector(sliderValueChang) forControlEvents:UIControlEventValueChanged];
        self.progreesView.leftIcon.image = [UIImage imageNamed:@"icon_pinl01"];
        self.progreesView.rightIcon.image = [UIImage imageNamed:@"icon_pinli02"];
        [self.bottomView addSubview:self.progreesView];
    }
    [timermange myTimerStart:paoma_timer_id timevalue:10 myFuncPtr:getspeed value:0 objclass:self];
}
-(void)viewDidDisappear:(BOOL)animated
{
    [timermange myTimerStart:paoma_timer_id timevalue:0 myFuncPtr:getspeed value:0 objclass:nil];//释放
}
void getspeed(int value,id objclass){
    [objclass mainspeed:value];
}

-(void)mainspeed:(int)value{//在主线程里发送
    if (paomaAspeedvalue!=self.progreesView.sliderView.value) {
        paomaAspeedvalue=self.progreesView.sliderView.value;
        unsigned char buf[500];
        memset(buf, 0, sizeof(buf));
        buf[0]='a';
        buf[1]=2;
        signed short int speed=100*(1-self.progreesView.sliderView.value);
        if(abs(speed)==0)speed=1;
        buf[2]=speed>>8;
        buf[3]=speed%0x100;
        [bleManage writeByte:[NSData dataWithBytes:buf length:4] index:0 time:0];//time为0表示立即发送
    }
    [timermange myTimerStart:paoma_timer_id timevalue:100 myFuncPtr:getspeed value:0 objclass:self];
}
#pragma mark - 频率输出
- (void)sliderValueChang {
    // 频率
    NSLog(@"%lf",self.progreesView.sliderView.value);
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}

#pragma mark - func
- (void)setupSubView {
    
    self.topView.layer.cornerRadius = 12;
    self.topViewLeftBtn.layer.cornerRadius = 12;
    self.topViewRightBtn.layer.cornerRadius = 12;
    
    self.topView.layer.borderWidth = 2;
    self.topViewLeftBtn.layer.borderWidth = 2;
    self.topViewRightBtn.layer.borderWidth = 2;
    
    self.topView.layer.borderColor = [UIColor zColorWithHex:0x430911].CGColor;
    self.topViewLeftBtn.layer.borderColor = [UIColor redColor].CGColor;
    self.topViewRightBtn.layer.borderColor = [UIColor clearColor].CGColor;
    
    [self.topViewLeftBtn setTitle:NSLocalizedString(@"LIGHT_Dengquan", nil) forState:UIControlStateNormal];
    [self.topViewRightBtn setTitle:NSLocalizedString(@"LIGHT_DengTiao", nil) forState:UIControlStateNormal];
    self.topViewLeftBtn.selected = YES;
    
    [self.collectionView registerNib:[UINib nibWithNibName:@"ZZLightViewCell" bundle:nil] forCellWithReuseIdentifier:kZZLightViewIdentifier];
    
    self.flowLayout.itemSize = CGSizeMake(158 * Z_Scale, 189 * Z_Scale);
    self.flowLayout.minimumInteritemSpacing = 10 * Z_Scale;
    self.flowLayout.minimumLineSpacing = 10 * Z_Scale;
    self.flowLayout.sectionInset = UIEdgeInsetsMake(0, 15 * Z_Scale, 0, 15 * Z_Scale);
    
}

- (void)isSelectModelForLight:(BOOL)isLightLine {

    if (isLightLine) {

      

    } else {

    }
}
#pragma mark - tableView D & D
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return self.lineGroupModel.models.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    ZZLightLineCell *cell = [tableView dequeueReusableCellWithIdentifier:kZZLightLineViewIdentifier];

    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    ZZLightLineModel *model = self.lineGroupModel.models[indexPath.row];
    cell.model = model;
    if (indexPath.row == 0) {

        cell.isAddCustomer = YES;
    }

    cell.setBtnClick = ^{

        
        
        ZZLightLineSettingVC *vc = [ZZLightLineSettingVC zStoryboardInstance];
        [vc view];
        if (indexPath.row == 0) {

            ZZLightLineModel *lineModel = [ZZLightLineModel new];
            
            lineModel.isSelect = NO;
            lineModel.title = @"默认名称";
            lineModel.model = LightLineModelCustom;
            lineModel.dicrection = LightLineDirectionLeft;
            for (NSInteger index = 0; index < 5; index++) {
                
                [lineModel.colorsGroup addObject:[NSMutableArray arrayWithArray:@[[ZZColorRGBA colorRGBAWithR:255.0 G:0 B:0 A:1],[ZZColorRGBA colorRGBAWithR:0 G:255.0 B:0 A:1],[ZZColorRGBA colorRGBAWithR:0 G:0 B:255.0 A:1]]]];
            }
            vc.isAddCustomer = YES;
            vc.model = lineModel;

        } else {

            vc.model = model;
        }
        
        Z_WEAK_SELF;
        
        vc.updateData = ^(ZZLightLineModel *model, BOOL isAddCustomer) {
          
            if (isAddCustomer) {
                
                [[ZZLightLineTool new].groupModel.models insertObject:model atIndex:1];
                [[ZZLightLineTool new] save];
                
                [weakSelf.tableView reloadData];
            } else {
                
                [[ZZLightLineTool new] save];
                [weakSelf.tableView reloadData];
            }
        };
        
        [self.navigationController pushViewController:vc animated:YES];
    };

    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

    return 98;
}


#pragma mark - collectionView D & D
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    return self.groupModel.models.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    ZZLightViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kZZLightViewIdentifier forIndexPath:indexPath];


    Z_WEAK_SELF;
    cell.addBtnClick = ^{
        
        ZZLightViewSettingVC *vc = [ZZLightViewSettingVC zStoryboardInstance];
        Z_WEAK_SELF;
        // 点击保存之后的输出的颜色
        vc.updateData = ^ (ZZLightViewCellModel *model) {
            
            
            [[ZZLightColorTool new].lightGroup.models insertObject:model atIndex:1];
            [[ZZLightColorTool new] save];
            
            [weakSelf.collectionView reloadData];
            
#pragma 设置完后如果要设置model的跑马可以设置
           UIColor *outputColors =  [ZZColorRGBA colorsFromRGBA:model.colors];
        };
        
        
        vc.view.backgroundColor;
        
        
        ZZLightViewCellModel *model4 = [ZZLightViewCellModel new];
        model4.title = NSLocalizedString(@"MUSIC_MuscicList_DefaultName", nil);
        model4.model = LightModelQiCai;
        
        model4.colorZuHeShu = 5;
        model4.tuoWeiLength = 0.2;
        model4.imageSize = CGSizeMake(130, 130);
        for (NSInteger index = 0; index < 5; index++) {
            
            [model4.colorsGroup addObject:[NSMutableArray arrayWithArray:@[[ZZColorRGBA colorRGBAWithR:255.0 G:255.0 B:0 A:1],[ZZColorRGBA colorRGBAWithR:0 G:255.0 B:0 A:1],[ZZColorRGBA colorRGBAWithR:255.0 G:0 B:0 A:1]]]];
        }
        [model4 reloadImage];
    
        
        
        vc.model =  model4;
        [self.navigationController pushViewController:vc animated:YES];
        
        
    };
    
    cell.setBtnClick = ^{
        
        ZZLightViewSettingVC *vc = [ZZLightViewSettingVC zStoryboardInstance];
        vc.view.backgroundColor;
        vc.model = weakSelf.groupModel.models[indexPath.row];
        vc.updateData = ^ (ZZLightViewCellModel *model){
            
            [[ZZLightColorTool new] save];
            [self.collectionView reloadData];
            
#pragma 设置完后如果要设置model的跑马可以设置
            UIColor *outputColors =  [ZZColorRGBA colorsFromRGBA:model.colors];
        };
        
        [self.navigationController pushViewController:vc animated:YES];
    };
    
    cell.model = self.groupModel.models[indexPath.row];
    
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.row == 0) {
        
        return;
    }
    unsigned char bufA[500],bufB[500];
    memset(bufA, 0, sizeof(bufA));memset(bufB, 0, sizeof(bufB));
    
    ZZLightViewCellModel *model = self.groupModel.models[indexPath.row];
    NSMutableArray *outPutColorA = [NSMutableArray array];
    NSMutableArray *outPutColorB = [NSMutableArray array];
    switch (model.model) {
        case LightModelQiCai:
        {
            bufA[2]=0;bufB[2]=0;
            int len=bleManage.LEDANum/model.colors.count;//每个色块的长度
            for (int j=0; j<3; j++) {
                for (int i=0; i<model.colors.count; i++) {
                    ZZColorRGBA *rgb=model.colors[i];
                    [outPutColorA addObject:[UIColor colorWithRed:rgb.R green:rgb.G blue: rgb.B alpha:1]];//
                }
                for (int z=(int)model.colors.count; z<len; z++) {
                    [outPutColorA addObject:[UIColor colorWithRed:1 green: 1 blue: 1 alpha:0]];
                }
                if (j<bleManage.LEDANum%model.colors.count) {
                    [outPutColorA addObject:[UIColor colorWithRed:1 green: 1 blue: 1 alpha:0]];
                }
            }
            len=bleManage.LEDBNum/model.colors.count;//每个色块的长度
            for (int j=0; j<3; j++) {
                for (int i=0; i<model.colors.count; i++) {
                    ZZColorRGBA *rgb=model.colors[i];
                    [outPutColorB addObject:[UIColor colorWithRed:rgb.R green:rgb.G blue: rgb.B alpha:1]];//
                }
                for (int z=(int)model.colors.count; z<len; z++) {
                    [outPutColorB addObject:[UIColor colorWithRed:1 green: 1 blue: 1 alpha:0]];
                }
                if (j<bleManage.LEDANum%model.colors.count) {
                    [outPutColorB addObject:[UIColor colorWithRed:1 green: 1 blue: 1 alpha:0]];
                }
            }
        } break;
        case LightModelTaiJi:
        {
            bufA[2]=0;bufB[2]=0;
            int len=bleManage.LEDANum/model.colors.count-1;//每个色块的长度
            for (int i=0; i<model.colors.count; i++) {
                ZZColorRGBA *rgb=model.colors[i];
                for (int j=0; j<len; j++) {
                    [outPutColorA addObject:[UIColor colorWithRed:rgb.R green: rgb.G blue: rgb.B alpha:1.0/((j+1)*1.5)]];
                }
                [outPutColorA addObject:[UIColor colorWithRed:1 green: 1 blue: 1 alpha:0]];
            }
            len=bleManage.LEDBNum/model.colors.count-1;//每个色块的长度
            for (int i=0; i<model.colors.count; i++) {
                ZZColorRGBA *rgb=model.colors[i];
                for (int j=0; j<len; j++) {
                    [outPutColorB addObject:[UIColor colorWithRed:rgb.R green: rgb.G blue: rgb.B alpha:1.0/((j+1)*1.5)]];
                }
                [outPutColorB addObject:[UIColor colorWithRed:1 green: 1 blue: 1 alpha:0]];
            }
        }break;
        case LightModelFengHuoLun:
        {
            bufA[2]=0;bufB[2]=0;
            int len=bleManage.LEDANum/model.colors.count-1;//每个色块的长度
            for (int i=0; i<model.colors.count; i++) {
                ZZColorRGBA *rgb=model.colors[i];
                [outPutColorA addObject:[UIColor colorWithRed:rgb.R green:rgb.G blue: rgb.B alpha:0]];//
                
                //中间亮，两头暗
                switch (len%3) {
                    case 2:
                    case 0:{
                        float z=1;
                        for (int j=0; j<len/2; j++) {
                            [outPutColorA addObject:[UIColor colorWithRed:rgb.R green: rgb.G blue: rgb.B alpha:z/(2*len)]];
                            z+=1;
                        }
                        z-=1;
                        [outPutColorA addObject:[UIColor colorWithRed:rgb.R green: rgb.G blue: rgb.B alpha:1]];//中间最亮
                        for (int j=0; j<len/2; j++) {
                            [outPutColorA addObject:[UIColor colorWithRed:rgb.R green: rgb.G blue: rgb.B alpha:z/(2*len)]];
                            z-=1;
                        }
                        
                    }
                        break;
                    case 1:
                    {
                        float z=1;
                        for (int j=0; j<len/2-1; j++) {
                            [outPutColorA addObject:[UIColor colorWithRed:rgb.R green: rgb.G blue: rgb.B alpha:z/(2*len)]];
                            z+=1;
                        }
                        z-=1;
                        [outPutColorA addObject:[UIColor colorWithRed:rgb.R green: rgb.G blue: rgb.B alpha:1]];//中间最亮
                        [outPutColorA addObject:[UIColor colorWithRed:rgb.R green: rgb.G blue: rgb.B alpha:1]];//中间最亮
                        for (int j=0; j<len/2-1; j++) {
                            [outPutColorA addObject:[UIColor colorWithRed:rgb.R green: rgb.G blue: rgb.B alpha:z/(2*len)]];
                            z-=1;
                        }
                    }
                        break;
                        
                }
                
                
            }
            len=bleManage.LEDBNum/model.colors.count-1;//每个色块的长度
            for (int i=0; i<model.colors.count; i++) {
                ZZColorRGBA *rgb=model.colors[i];
                [outPutColorB addObject:[UIColor colorWithRed:rgb.R green:rgb.G blue: rgb.B alpha:0]];//
                
                //中间亮，两头暗
                switch (len%3) {
                    case 2:
                    case 0:{
                        float z=1;
                        for (int j=0; j<len/2; j++) {
                            [outPutColorB addObject:[UIColor colorWithRed:rgb.R green: rgb.G blue: rgb.B alpha:z/(2*len)]];
                            z+=1;
                        }
                        z-=1;
                        [outPutColorB addObject:[UIColor colorWithRed:rgb.R green: rgb.G blue: rgb.B alpha:1]];//中间最亮
                        for (int j=0; j<len/2; j++) {
                            [outPutColorB addObject:[UIColor colorWithRed:rgb.R green: rgb.G blue: rgb.B alpha:z/(2*len)]];
                            z-=1;
                        }
                        
                    }
                        break;
                    case 1:
                    {
                        float z=1;
                        for (int j=0; j<len/2-1; j++) {
                            [outPutColorB addObject:[UIColor colorWithRed:rgb.R green: rgb.G blue: rgb.B alpha:z/(2*len)]];
                            z+=1;
                        }
                        z-=1;
                        [outPutColorB addObject:[UIColor colorWithRed:rgb.R green: rgb.G blue: rgb.B alpha:1]];//中间最亮
                        [outPutColorB addObject:[UIColor colorWithRed:rgb.R green: rgb.G blue: rgb.B alpha:1]];//中间最亮
                        for (int j=0; j<len/2-1; j++) {
                            [outPutColorB addObject:[UIColor colorWithRed:rgb.R green: rgb.G blue: rgb.B alpha:z/(2*len)]];
                            z-=1;
                        }
                    }
                        break;
                        
                }
                
                
            }
        }break;
        case LightModelFugai:
        {
            bufA[2]=1;bufB[2]=1;
            //            int len=bleManage.LEDANum/model.colors.count-1;//每个色块的长度
            //            for (int i=0; i<model.colors.count; i++) {
            //                ZZColorRGBA *rgb=model.colors[i];
            //                for (int j=0; j<len; j++) {
            //                    [outPutColor addObject:[UIColor colorWithRed:rgb.R green: rgb.G blue: rgb.B alpha:1.0/((j+1)*1.5)]];
            //                }
            //                [outPutColor addObject:[UIColor colorWithRed:1 green: 1 blue: 1 alpha:0]];
            //            }
        }break;
        case LightModelTiaoBian:
        {
            bufA[2]=2;bufB[2]=2;
            //            int len=bleManage.LEDANum/model.colors.count-1;//每个色块的长度
            //            for (int i=0; i<model.colors.count; i++) {
            //                ZZColorRGBA *rgb=model.colors[i];
            //                for (int j=0; j<len; j++) {
            //                    [outPutColor addObject:[UIColor colorWithRed:rgb.R green: rgb.G blue: rgb.B alpha:1.0/((j+1)*1.5)]];
            //                }
            //                [outPutColor addObject:[UIColor colorWithRed:1 green: 1 blue: 1 alpha:0]];
            //            }
        }break;
    }
    //第一字节 led编号
    //第二字节 指令类型 0获取led个数 1设置参数 2设置速率
    //第三字节 类型，0跑马 1覆盖 2跳变
    //第四、五字节 变化速率
    //第六字节以后 颜色数组
    signed short int speed=200*(1-model.pinLv)*(model.isAnticlockwise?1:-1);
    if(abs(speed)==0)speed=(model.isAnticlockwise?1:-1);
    bufA[0]='a';
    bufA[1]=1;//设置参数
    bufA[3]=speed>>8;
    bufA[4]=speed%0x100;
    int i=5;
    for (UIColor *color in outPutColorA) {
        NSString *RGBValue = [NSString stringWithFormat:@"%@",color];
        NSArray *RGBArr = [RGBValue componentsSeparatedByString:@" "];
        float r = [[RGBArr objectAtIndex:1] floatValue]*[[RGBArr objectAtIndex:4] floatValue];
        float g = [[RGBArr objectAtIndex:2] floatValue]*[[RGBArr objectAtIndex:4] floatValue];
        float b = [[RGBArr objectAtIndex:3] floatValue]*[[RGBArr objectAtIndex:4] floatValue];
        bufA[i]=r;bufA[i+1]=g;bufA[i+2]=b;
        i+=3;
    }
    speed=200*(1-model.pinLv)*(model.isAnticlockwise?1:-1);
    if(abs(speed)==0)speed=(model.isAnticlockwise?1:-1);
    bufB[0]='b';
    bufB[1]=1;//设置参数
    bufB[3]=speed>>8;
    bufB[4]=speed%0x100;
    i=5;
    for (UIColor *color in outPutColorB ) {
        NSString *RGBValue = [NSString stringWithFormat:@"%@",color];
        NSArray *RGBArr = [RGBValue componentsSeparatedByString:@" "];
        float r = [[RGBArr objectAtIndex:1] floatValue]*[[RGBArr objectAtIndex:4] floatValue];
        float g = [[RGBArr objectAtIndex:2] floatValue]*[[RGBArr objectAtIndex:4] floatValue];
        float b = [[RGBArr objectAtIndex:3] floatValue]*[[RGBArr objectAtIndex:4] floatValue];
        bufB[i]=r;bufB[i+1]=g;bufB[i+2]=b;
        i+=3;
    }
    NSData *dat=[NSData dataWithBytes:bufB length:bleManage.LEDBNum*3+5];
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        [NSThread sleepForTimeInterval:0.5];
        dispatch_async(dispatch_get_main_queue(), ^{
            [bleManage writeByte:dat index:0 time:0];//time为0表示立即发送
        });
        
    });
    [bleManage writeByte:[NSData dataWithBytes:bufA length:bleManage.LEDANum*3+5] index:0 time:0];//time为0表示立即发送
}

#pragma mark - action
- (void)rightNavItemClick {
    
    if (self.devicemanager) {
        
        [self.devicemanager removeFromSuperview];
        self.devicemanager = nil;
        return;
    }
    
    ZZDeviceManager *manager = [ZZDeviceManager xibInstance];
    manager.vc = self;
    
    self.devicemanager = manager;
    manager.frame = CGRectMake(Z_SCREEN_WIDTH, 64, Z_SCREEN_WIDTH, Z_SCREEN_HEIGHT - 64);
    [self.tabBarController.view addSubview:manager];
    
    [UIView animateWithDuration:0.4 animations:^{
        
        manager.x = 0;
    }];
}


- (IBAction)topViewLeftBtnClick:(UIButton *)sender {

    self.tableView.hidden = YES;
    self.collectionView.hidden = NO;
    if (sender.selected == YES) {


        return;
    } else {
        
        sender.selected = YES;
        sender.layer.borderColor = [UIColor redColor].CGColor;
        self.topViewRightBtn.layer.borderColor = [UIColor clearColor].CGColor;
        self.topViewRightBtn.selected  = NO;
    }
}

- (IBAction)topViewRightBtnClick:(UIButton *)sender {
    
    self.tableView.hidden = NO;
    self.collectionView.hidden = YES;
    if (sender.selected == YES) {
        
        return;
    } else {
        
        sender.selected = YES;
        sender.layer.borderColor = [UIColor redColor].CGColor;
        self.topViewLeftBtn.layer.borderColor = [UIColor clearColor].CGColor;
        self.topViewLeftBtn.selected  = NO;
    }
}




#pragma mark - set & get
- (ZZLightViewGroupModel *)groupModel {
    
    if(!_groupModel){
        
        _groupModel = [ZZLightColorTool new].lightGroup;
    }
    return _groupModel;
}

- (ZZLightLineGroupModel *)lineGroupModel {

    if (!_lineGroupModel) {

        _lineGroupModel = [[ZZLightLineTool new] groupModel];
    }
    return _lineGroupModel;
}

@end

